<?php

namespace App\Models\Shop;

use App\Models\BaseModel;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

class ShopStatsModel extends BaseModel
{
    protected $table = 'shop_stats';

    protected $primaryKey = 'id';

    public $dateFormat = 'U';



    public function addShopStats($store_id,$sales_count,$view_count,$order_count,$sales_money,$goods_zone){

        $count_date= Carbon::today()->timestamp;

        $data=array(
            'stats_date'=>$count_date,
            'store_id' =>$store_id,
            'goods_zone'=>$goods_zone
        );

        $where['stats_date'] = $count_date;
        $where['store_id'] = $store_id;
        $where['goods_zone'] = $goods_zone;

        $data['sales_count']=DB::raw('IFNULL(`sales_count`,0)+'.$sales_count);

        $data['view_count']=DB::raw('IFNULL(`view_count`,0)+'.$view_count);

        $data['order_count']=DB::raw('IFNULL(`order_count`,0)+'.$order_count);

        $data['sales_money']=DB::raw('IFNULL(`sales_money`,0)+'.$sales_money);

        return self::updateOrInsert($where,$data);

    }

}
